﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using YamlDotNet.RepresentationModel;

public static class YamlExt
{
    public static AssetYamlBase GetValueAssetYamlBase(this YamlNode node)
    {
        YamlMappingNode map_node = node as YamlMappingNode;

        AssetYamlBase bb = new AssetYamlBase();

        bb.FileId = map_node.Children[new YamlScalarNode("fileID")].GetValue();
        if (int.Parse(bb.FileId) > 0)//== 0 就是还没有资源，没有guid等参数
        {
            bb.Guid = map_node.Children[new YamlScalarNode("guid")].GetValue();
            bb.Type = int.Parse(map_node.Children[new YamlScalarNode("type")].GetValue());
        }
        return bb;
    }
    [System.Obsolete("简单的能用")]
    public static string GetValueFileId(this YamlNode node)
    {
        YamlMappingNode map_node = node as YamlMappingNode;

        string fileId = "";
        //TODO:暂时不知道怎么取第一个节点
        foreach (var k_v in map_node.Children)
        {
            //取一个简单值，绕晕你，再绕晕你。。。。就问你服不服
            fileId = ((YamlScalarNode)k_v.Value).Value;
            break;
        }
        return fileId;
    }
    public static string GetValue(this YamlNode node)
    {
        YamlScalarNode text_node = node as YamlScalarNode;
        return text_node.Value;
    }
    public static string GetKey(this YamlNode node)
    {
        YamlScalarNode tex_node = node as YamlScalarNode;
        return tex_node.ToString();
    }
}
